<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
if (!isset($_SESSION['member_id'])) {
    echo"<script type='text/javascript'>top.window.location='index.php';</script>";
} else {
    $memberID = $_SESSION['member_id'];
}
if (isset($_SESSION['lang']))
    require_once "./language_files/conferencePage2_" . $_SESSION['lang'] . ".php";
else
    require_once "./language_files/conferencePage2_en.php";
?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <link href="style3.css" rel="stylesheet" type="text/css" />
        <link href="jquery-ui-all.css" rel="stylesheet" type="text/css" />
        <?php include "jquery.php";
        include "functions.php";
        ?>
        <script type="text/javascript" src="jquery-ui-1.8.21.custom.min.js"></script>
        <script type="text/javascript" src="functions.js"></script>
        <script type="text/javascript">
            //<![CDATA[
            function validateFormat(datestring)
            {
                if(datestring==undefined)
                    return false;
                regexp=/^20(1[0-9]|2[0-9]|3[0-8])(-|\/)\d{2}(-|\/)\d{2}$/;
                if(datestring.match(regexp)==null)
                    return false;
                else
                    return true;
            }
            $(document).ready(function()
            {
                check_top();
                conference=$("#h1").attr("class");

                $("#description_label").html(2000-$("#description_area").html().length);
                $("#call_papers_label").html(200-$("#call_papers_area").html().length);
                $(".subscribe").bind("click",function()
                {
                    $(this).attr("disabled", "disabled");
                    label = top.document.getElementById("num_requests");
                    $.ajax({
                        type:"POST",
                        url: "conferencePageServer.php",
                        data:{conference_id:conference,role:$(this).attr("name")},
                        success:function(response)
                        {
                            if(response=="1")
                            {
                                alert("Your request has been logged and pending approval");
                                main_iframe=top.document.getElementById("collabsoft");
                                $(main_iframe).attr("src", $(main_iframe).attr("src"));
                            }
                            else if(response=="0")
                                alert("An error has occurred during placing your request please try again later");
                            else
                                alert(response);
                        }
                    });
                    $.ajax ({
                    type: 'POST',
                    url:  'num_requests.php',
                    success: function(response) {
                        if(response == "0") {
                            $("#num_requests").html('');
                            $("#num_requests").removeClass("num_requests");
                        } else {
                            $("#num_requests").text(response);
                            $("#num_requests").addClass("num_requests");
                        }
                    }
                });
                });
                $("#edit_info").one("click", function()
                {
                    main_iframe=top.document.getElementById("collabsoft");
                    $(main_iframe).height($(main_iframe).height()+200);
                    place=$("#place_td").html();
                    description=$("#description_area").html();
                    call_papers=$("#call_papers_area").html();
                    review_start=$("#review_start_td").html();
                    review_end=$("#review_end_td").html();
                    short_paper=$("#short_paper_td").html();
                    long_paper=$("#long_paper_td").html();
                    poster=$("#poster_td").html();
                    image=$("#image_td").html();
                    video=$("#video_td").html();
                    $("#description_label").removeClass("invisible");
                    $("#call_papers_label").removeClass("invisible");
                    $.ajax({
                        type:"POST",
                        url: "conferencePageServer.php",
                        data:{get_place:"POST"},
                        success:function(response)
                        {
                            $("#place_td").html("<select id='place'><optgroup label='Countries'>"+response+"</optgroup></select>");
                            $("#place option:contains('"+place+"')").attr("selected","selected");
                        }
                    });
                    review_start_change=false;
                    review_end_change=false;
                    short_paper_change=false;
                    long_paper_change=false;
                    poster_change=false;
                    image_change=false;
                    video_change=false;
                    $("#description_area").remove();
                    $("#description_td").prepend("<textarea id='description_area' cols='50' rows='5'>"+description+"</textarea>");
                    $("#description_label").html(2000-$("#description_area").val().length);
                    $("#description_area").bind("keyup input paste",function()
                    {
                        len=$("#description_area").val().length;
                        if(len>2000)
                        {
                            $("#description_area").val($("#description_area").val().substr(0,2000));
                        }
                        $("#description_label").html(2000-len);
                    });
                    $("#call_papers_area").remove();
                    $("#call_papers_td").prepend("<textarea id='call_papers_area' cols='50' rows='5'>"+call_papers+"</textarea>");
                    $("#call_papers_label").html(200-$("#call_papers_area").val().length);
                    $("#call_papers_area").bind("keyup input paste", function()
                    {
                        len=$("#call_papers_area").val().length;
                        if(len>200)
                        {
                            $("#call_papers_area").val($("#call_papers_area").val().substr(0,200));
                        }
                        $("#call_papers_label").html(200-len);
                    });
                    $("#conf_date_td").html("<strong class='red'>Conference date (unchangeable already passed)</strong>");
                    $("#review_start_td").html("<input size='26' type='text' onchange='javascript: review_start_change=true;' id='review_start' value='"+review_start+"' /><label class='error' style='color:red;' id='review_start_label'></label>");
                    $("#review_end_td").html("<input type='text' size='26' onchange='javascript: review_end_change=true;' id='review_end' value='"+review_end+"' /><label class='error' style='color:red;' id='review_end_label'></label>");
                    $("#short_paper_td").html("<input type='text' size='26' onchange='javascript: short_paper_change=true;' id='short_paper' value='"+short_paper+"' /><label class='error' style='color:red;' id='short_paper_label'></label>");
                    $("#long_paper_td").html("<input type='text' size='26' onchange='javascript: long_paper_change=true;' id='long_paper' value='"+long_paper+"' /><label class='error' style='color:red;' id='long_paper_label'></label>");
                    $("#poster_td").html("<input type='text' size='26' onchange='javascript: poster_change=true;' id='poster' value='"+poster+"' /><label class='error' style='color:red;' id='poster_label'></label>");
                    $("#image_td").html("<input type='text' size='26' onchange='javascript: image_change=true;' id='image' value='"+image+"' /><label class='error' style='color:red;' id='image_label'></label>");
                    $("#video_td").html("<input type='text' size='26' onchange='javascript: video_change=true;' id='video' value='"+video+"' /><label class='error' style='color:red;' id='video_label'></label>");

                    $("input[type=text]").datepicker({ dateFormat: "yy-mm-dd" });

                    $("#options").html("<button id='save'>Save Information</button>");
                    $("#save").bind("click",function()
                    {
                        $(this).attr("disabled", "disabled");
                        $(".error").html("");
                        place=$("#place").val();
                        description=$("#description_area").val();
                        call_papers=$("#call_papers_area").val();
                        review_start=$("#review_start").val();
                        review_end=$("#review_end").val();
                        short_paper=$("#short_paper").val();
                        long_paper=$("#long_paper").val();
                        poster=$("#poster").val();
                        image=$("#image").val();
                        video=$("#video").val();

                        curdate=new Date();
                        review_start_date=new Date(review_start);
                        review_end_date=new Date(review_end);
                        short_paper_date=new Date(short_paper);
                        long_paper_date=new Date(long_paper);
                        poster_date=new Date(poster);
                        image_date=new Date(image);
                        video_date=new Date(video);

                        ready=true;
                        if((!validateFormat(review_start) || review_start_date<=curdate) && review_start_change)
                        {
                            $("#review_start_label").html("<?php echo $lang['message_1']; ?>");
                            ready=false;
                        }
                        else if((!validateFormat(review_end) || review_end_date<=review_start_date) && (review_end_change || review_start_change))
                        {
                            $("#review_end_label").html("<?php echo $lang['message_2']; ?>");
                            ready=false;
                        }
                        else if(review_end_date<=curdate && review_end_change)
                        {
                            $("#review_end_label").html("<?php echo $lang['message_3']; ?>");
                            ready=false;
                        }
                        else if((!validateFormat(short_paper) || short_paper_date>=review_start_date) && (short_paper_change || review_start_change))
                        {
                            if(short_paper!=undefined)
                            {
                                $("#short_paper_label").html("<?php echo $lang['message_4']; ?>");
                                ready=false;
                            }
                        }
                        else if(short_paper_date<=curdate && short_paper_change)
                        {
                            if(short_paper!=undefined)
                            {
                                $("#short_paper_label").html("<?php echo $lang['message_1']; ?>");
                                ready=false;
                            }
                        }
                        else if((!validateFormat(long_paper) || long_paper_date>=review_start_date) && (long_paper_change || review_start_change))
                        {
                            if(long_paper!=undefined)
                            {
                                $("#long_paper_label").html("<?php echo $lang['message_5']; ?>");
                                ready=false;
                            }
                        }
                        else if(long_paper_date<=curdate && long_paper_change)
                        {
                            if(long_paper!=undefined)
                            {
                                $("#long_paper_label").html("<?php echo $lang['message_1']; ?>");
                                ready=false;
                            }
                        }
                        else if((!validateFormat(poster) || poster_date>=review_start_date) && (poster_change || review_start_change))
                        {
                            if(poster!=undefined)
                            {
                                $("#poster_label").html("<?php echo $lang['message_5']; ?>");
                                ready=false;
                            }
                        }
                        else if(poster_date<=curdate && poster_change)
                        {
                            if(poster!=undefined)
                            {
                                $("#poster_label").html("<?php echo $lang['message_1']; ?>");
                                ready=false;
                            }
                        }
                        else if((!validateFormat(image) || image_date>=review_start_date) && (image_change || review_start_change))
                        {
                            if(image!=undefined)
                            {
                                $("#image_label").html("<?php echo $lang['message_5']; ?>");
                                ready=false;
                            }
                        }
                        else if(image_date<=curdate && image_change)
                        {
                            if(image!=undefined)
                            {
                                $("#image_label").html("<?php echo $lang['message_1']; ?>");
                                ready=false;
                            }
                        }
                        else if((!validateFormat(video) || video_date>=review_start_date) && (video_change || review_start_change))
                        {
                            if(video!=undefined)
                            {
                                $("#video_label").html("<?php echo $lang['message_5']; ?>");
                                ready=false;
                            }
                        }
                        else if(video_date<=curdate && video_change)
                        {
                            if(video!=undefined)
                            {
                                $("#video_label").html("<?php echo $lang['message_1']; ?>");
                                ready=false;
                            }
                        }
                        if(ready)
                        {
                            $.ajax({
                                type:"POST",
                                url: "conferencePageServer.php",
                                data:{update:true,conference_id:conference,country:place,desc:description,call:call_papers,rev_start:review_start,rev_end:review_end,short_paper_sub:short_paper,long_paper_sub:long_paper,poster_sub:poster,image_sub:image,video_sub:video},
                                success: function(response)
                                {
                                    if(response=="1")
                                    {
                                        alert("Conference Information saved successfully");
                                        main_iframe=top.document.getElementById("collabsoft");
                                        $(main_iframe).height($(main_iframe).height()-200);
                                        $(main_iframe).attr("src", $(main_iframe).attr("src"));
                                    }
                                    else
                                    {
                                        alert("an error has occured during the process please try again later\n"+response);
                                        $(this).removeAttr("disabled");
                                    }
                                }
                            });
                        }
                        else
                            $(this).removeAttr("disabled");
                    });
                });
            });
            //]]>
        </script>
        <title>Conference Page</title>
    </head>
    <body>
        <?php
        include "statics.php";
        $conf_id = $_GET['conference_id'];
        $rsLongName = rsSelect("long_name,conference_id", "conference", array("conference_id=", $conf_id));
        if (is_string($rsLongName))
            echo $rsLongName;
        else {
            if (mysql_num_rows($rsLongName) > 0) {
                $row = mysql_fetch_assoc($rsLongName);
                $long_name = formatText_safe($row['long_name']);
                echo "<h1 id='h1' class='{$row['conference_id']}'>" . $long_name . "</h1>";
            }
        }
        ?>
        <table>
            <tr>
                <td style="border:0px;">
                    <h2 style="border:5px solid;border-radius: 5px;"><?php echo $lang['title']; ?></h2>
                </td>
                <?php
                if (bOrganizer($_SESSION['member_id'], $_GET['conference_id'])) {
                    echo "<td style='border:0px;'><button id='edit_info'>" . $lang['edit'] . "</button></td>";
                }
                ?>
            </tr>
            <tr>
                <td><strong><?php echo $lang['place']; ?></strong></td>
                <?php
                $rsPlace = rsSelect("place", "conference", array("conference_id=", $_GET['conference_id']));
                if (is_string($rsPlace))
                    echo $rsPlace;
                else {
                    $row = mysql_fetch_assoc($rsPlace);
                    $rsCountry = rsSelect("country_name", "country", array("country_id=", $row['place']));
                    if (is_string($rsCountry))
                        echo $rsCountry;
                    else {
                        $row = mysql_fetch_assoc($rsCountry);
                        echo "<td id='place_td'>" . $row['country_name'] . "</td>";
                    }
                }
                ?>
            </tr>
            <tr>
                <td><strong><?php echo $lang['description']; ?></strong></td>
                <td id="description_td">
                    <?php
                    $rsDesc = rsSelect("description", "conference", array("conference_id=", $_GET['conference_id']));
                    if (is_string($rsDesc))
                        echo $rsDesc;
                    else {
                        $row = mysql_fetch_assoc($rsDesc);
                        echo "<span  id='description_area'>" . sEscape($row['description']) . "</span><br/>";
                        $q = mysql_query("SELECT creator_id FROM conference WHERE conference_id = '$conf_id' AND creator_id = '$memberID'");
                        $count = mysql_num_rows($q);
                        if ($count != 0) {
                            echo " <label style='border:2px solid #003366;' class='invisible' id='description_label'>2000</label>";
                        }
                    }
                    ?>
                </td>
            </tr>
            <tr>
                <td><strong><?php echo $lang['call_for_papers']; ?></strong></td>
                <td id="call_papers_td">
                    <?php
                    $rsCall = rsSelect("call_for_papers_text", "conference", array("conference_id=", $_GET['conference_id']));
                    if (is_string($rsCall))
                        echo $rsCall;
                    else {
                        $row = mysql_fetch_assoc($rsCall);
                        echo "<span id='call_papers_area'>" . $row['call_for_papers_text'] . "</span><br/>";
                        $q = mysql_query("SELECT creator_id FROM conference WHERE conference_id = '$conf_id' AND creator_id = '$memberID'");
                        $count = mysql_num_rows($q);
                        if ($count != 0) {
                            echo " <label style='border:2px solid #003366;' class='invisible' id='call_papers_label'>200</label>";
                        }
                    }
                    ?>
                </td>
            </tr>
            <tr>
                <td style="border:0px;">
                    <h2 style="border:5px solid;border-radius: 5px;"><?php echo $lang['timeline']; ?></h2>
                </td>
            </tr>
            <tr>
                <td id="conf_date_td"><strong><?php echo $lang['conference_date']; ?></strong></td>
                <?php
                $rsConfDate = rsSelect("conference_date", "conference", array("conference_id=", $_GET['conference_id']));
                if (is_string($rsConfDate))
                    echo $rsConfDate;
                else {
                    $row = mysql_fetch_assoc($rsConfDate);
                    echo "<td id='conference_date_td'>" . $row['conference_date'] . "</td>";
                }
                ?>
            </tr>
            <tr>
                <td><strong><?php echo $lang['review_sdate']; ?></strong></td>
                <?php
                $rsReviewStart = rsSelect("rev_startDate", "conference", array("conference_id=", $_GET['conference_id']));
                if (is_string($rsReviewStart))
                    echo $rsReviewStart;
                else {
                    $row = mysql_fetch_assoc($rsReviewStart);
                    echo "<td id='review_start_td'>" . $row['rev_startDate'] . "</td>";
                }
                ?>
            </tr>
            <tr>
                <td><strong><?php echo $lang['review_edate']; ?></strong></td>
                <?php
                $rsReviewEnd = rsSelect("rev_endDate", "conference", array("conference_id=", $_GET['conference_id']));
                if (is_string($rsReviewEnd))
                    echo $rsReviewEnd;
                else {
                    $row = mysql_fetch_assoc($rsReviewEnd);
                    echo "<td id='review_end_td'>" . $row['rev_endDate'] . "</td>";
                }
                ?>
            </tr>
            <tr>
                <td style="border:0px;">
                    <h2 style="border:5px solid;border-radius: 5px;"><?php echo $lang['deadline']; ?></h2>
                </td>
            </tr>
            <?php
            $rsCategories = rsSelect("*", "conference_category", array("conference_id=", $_GET['conference_id']));
            if (is_string($rsCategories))
                echo $rsCategories;
            else {
                while ($row = mysql_fetch_assoc($rsCategories)) {
                    $rsCategoryName = rsSelect("category", "category", array("category_id=", $row['category_id']));
                    if (is_string($rsCategoryName))
                        echo $rsCategoryName;
                    else {
                        $rowCategoryName = mysql_fetch_assoc($rsCategoryName);
                        echo "<tr><td><strong>" . $rowCategoryName['category'] . "</strong></td>";
                        switch ($rowCategoryName['category']) {
                            case "Short Paper":echo "<td id='short_paper_td'>" . $row['submission_date'] . "</td></tr>";
                                break;
                            case "Long Paper":echo "<td id='long_paper_td'>" . $row['submission_date'] . "</td></tr>";
                                break;
                            case "Poster":echo "<td id='poster_td'>" . $row['submission_date'] . "</td></tr>";
                                break;
                            case "Image":echo "<td id='image_td'>" . $row['submission_date'] . "</td></tr>";
                                break;
                            case "Video":echo "<td id='video_td'>" . $row['submission_date'] . "</td></tr>";
                                break;
                        }
                    }
                }
            }
            ?>
            <tr>
                <td id="options" colspan="2" style="border-color: #003366;">
                    <?php
                    $bRet = bOrganizer($_SESSION['member_id'], $_GET['conference_id']);
                    if (is_string($bRet)) {
                        echo $bRet;
                        exit();
                    }
                    if (!$bRet) {
                        $bRet = bPending($_SESSION['member_id'], $_GET['conference_id'], "organizer");
                        if (is_string($bRet)) {
                            echo $bRet;
                            exit();
                        }
                        if ($bRet) {
                            echo "<button class='back_red' disabled='disabled'>" . $lang['button_1'] . "</button> ";
                        } else {
                            echo "<button class='subscribe' name='organizer'>" . $lang['button_2'] . "</button> ";
                        }
                    } else {
                        echo "<button class='back_green' disabled='disabled'>" . $lang['button_3'] . "</button> ";
                    }
                    $bRet = bAuthorAll($_SESSION['member_id'], $_GET['conference_id']);
                    if (is_string($bRet)) {
                        echo $bRet;
                        exit();
                    }
                    if (!$bRet) {
                        $bRet = bPending($_SESSION['member_id'], $_GET['conference_id'], "author");
                        if (is_string($bRet)) {
                            echo $bRet;
                            exit();
                        }
                        if ($bRet) {
                            echo "<button class='back_red' disabled='disabled'>" . $lang['button_4'] . "</button> ";
                        } else {
                            echo "<button class='subscribe' name='author'>" . $lang['button_5'] . "</button> ";
                        }
                    } else {
                        echo "<button class='back_green' disabled='disabled'>" . $lang['button_6'] . "</button> ";
                    }
                    $bRet = bReviewerAll($_SESSION['member_id'], $_GET['conference_id']);
                    if (is_string($bRet)) {
                        echo $bRet;
                        exit();
                    }
                    if (!$bRet) {
                        $bRet = bPending($_SESSION['member_id'], $_GET['conference_id'], "reviewer");
                        if (is_string($bRet)) {
                            echo $bRet;
                            exit();
                        }
                        if ($bRet) {
                            echo "<button class='back_red' disabled='disabled'>" . $lang['button_7'] . "</button> ";
                        } else {
                            echo "<button class='subscribe' name='reviewer'>" . $lang['button_8'] . "</button> ";
                        }
                    } else {
                        echo "<button class='back_green' disabled='disabled'>" . $lang['button_9'] . "</button> ";
                    }
                    ?>
                </td>
            </tr>
        </table>
    </body>
</html>
